/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.teste;

import br.com.modelo.Estado;
import br.com.modelo.Governador;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author egberto
 */
public class AdicionaEstadoGovernador {
    
    public static void main(String args[]){
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("default");
        EntityManager manager = factory.createEntityManager();
        
        manager.getTransaction().begin();
        
        Governador g1 = manager.find(Governador.class, 1l);
        Estado e1 = g1.getEstado();
        
        Governador g = new Governador();
        g.setNome("Rafael Faustino");
        
        Estado e = new Estado();
        e.setNome("São Paulo");
        e.setGovernador(g);
        
        manager.persist(g);
        manager.persist(e);
        
        manager.getTransaction().commit();
        
        manager.close();
        factory.close();
    }
    
}
